package services

import (
	"github.com/goAdminMicroService/internal/app/details/repositories"
	"github.com/goAdminMicroService/internal/pkg/models"
	"github.com/pkg/errors"
	"go.uber.org/zap"
)

type DetailsService interface {
	Get(id uint64) (*models.Detail, error)
}

type DefaultDetailsService struct {
	logger     *zap.Logger
	Repository repositories.DetailsRepository
}

func NewDetailService(logger *zap.Logger, repository repositories.DetailsRepository) DetailsService {
	return &DefaultDetailsService{
		logger:     logger.With(zap.String("type", "DefaultDetailsService")),
		Repository: repository,
	}
}

func (s *DefaultDetailsService) Get(id uint64) (*models.Detail, error) {
	p, err := s.Repository.Get(id)
	if err != nil {
		return nil, errors.Wrap(err, "detail service get detail error")
	}
	return p, nil
}
